package com.zq.blog_serve.entity;

import lombok.Data;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;
import java.util.Collections;

@Data
public class LoginUser implements UserDetails {

    private static final long serialVersionUID = 1L;

    private SysUser sysUser;

    /**
     * tokenID
     */
    private String token;

    /**
     * 登录时间
     */
    private Long loginTime;

    /**
     * 过期时间
     */
    private Long expireTime;

    public LoginUser(SysUser sysUser) {
        this.sysUser = sysUser;
    }

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return Collections.emptyList();
    }

    @Override
    public String getPassword() {
        return sysUser.getPwd();
    }

    @Override
    public String getUsername() {
        return sysUser.getUserName();
    }

    @Override
    public boolean isAccountNonExpired() { // 账户是否没有过期
        return true;
    }

    @Override
    public boolean isAccountNonLocked() {// 用户是否没有锁定
        return true;
    }

    @Override
    public boolean isCredentialsNonExpired() {// 当前账号证书（密码）是否过期
        return true;
    }

    @Override
    public boolean isEnabled() {  // 用户是否启用
        return true;
    }
}
